<?php
	/**
	 *	KLF Framework
	 *
	 *	Written by Kristian Oye <kristianoye@gmail.com> on Oct 22, 2011
	 *	Copyright (C) 2010-2011
	 */
	namespace KLF\System\Test
	{
		class KUnitMethodOutcome
		{
			const SUCCESS = 0;
			
			const FAILURE = 1;
			
			const EXCEPTION = 2;
			
			const SKIPPED = 3;
		}
		
		/**
		 * Records the result of a single test method.
		 * 
		 * @author Kristian Oye <kristianoye@gmail.com>
		 * @since 0.2
		 */
		class KUnitMethodResult
		{
			public $_MethodName;
			
			public $_Outcome;
			
			public $_Output;
			
			public $_TimeEnd;
			
			public $_TimeStart;
			
			public function __construct($methodName)
			{
				$this->_MethodName = $methodName;
				$this->_Outcome = KUnitMethodOutcome::SKIPPED;
				$this->_Output = array(); 
			}
			
			public function ElapsedTime()
			{
				return ($this->_TimeEnd - $this->_TimeStart);
			}
			
			public function Output($strmsg='')
			{
				array_push($this->_Output, $strmsg);
			}
			
			public function TimeStart()
			{
				$this->_TimeStart = microtime(TRUE);
			}
			
			public function TimeEnd()
			{
				$this->_TimeEnd = microtime(TRUE);
			}
			
			public function __toString()
			{
				return sprintf("%s(Name: %s, Time: %f, Result: %s)",
					get_class($this), $this->_MethodName, $this->ElapsedTime(), $this->_Outcome);
			}
		}
		
		/**
		 *  Class KUnitTestResult
		 *
		 *  Records the results for a particular KUnitTestCase
		 *
		 *  @package KLF\System\Test
		 *  @access public
		 *  @author Kristian Oye <kristianoye@gmail.com>
		 *  @since 0.2
		 */
		class KUnitTestResult
		{
			public $_Results;
			
			public $_TestName;
			
			public function __construct($testName = '')
			{
				$this->_TestName = $testName;
				$this->_Results = array();
			}
			
			/**
			 * Creates and returns a new KUnitMethodResult
			 *
			 * @author Kristian Oye <kristianoye@gmail.com>
			 * @since 0.2
			 * @return KUnitMethodResult The named KUnitMethodResult object
			*/
			public function GetMethodResult($methodName = '')
			{
				if (!isset($this->_Results[$methodName]))
				{
					$this->_Results[$methodName] = new KUnitMethodResult($methodName);
				}
				return $this->_Results[$methodName];
			}
		}
	}
